package ModelLayer;

import java.util.*;

public class LeaseContainer
{
    private ArrayList<Lease> leaseContainer;
    private static LeaseContainer instance;

    private LeaseContainer(){
        leaseContainer = new ArrayList<Lease>();
    }

    public static LeaseContainer getInstance(){
        if(instance == null){
            instance = new LeaseContainer();
        }
        return instance;
    }

    public void addLease(Lease lease){
        leaseContainer.add(lease);
    }

    public Lease findLeaseById(int id){
        Lease pObject = null;
        int index = 0;
        boolean found = false;
        while(index < leaseContainer.size() && !found)
        {
            pObject = leaseContainer.get(index); 
            if(pObject.getId()== id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
        if(found){
            return leaseContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public ArrayList<Lease> getLeaseList(){
        return leaseContainer;
    }
    
    public void deleteLease(Lease p){
        if(leaseContainer.contains(p))
            leaseContainer.remove(p);
    }
}
